package com.superteam.mac.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.RowMapper;

import com.superteam.mac.mode.AlarmRec;

public class AlarmRecDAO extends BaseDAO {

	@SuppressWarnings("unchecked")
	public List<AlarmRec> findAllIndexConfig(String workshop,String machineCode,String startTime,String endTime)
	{
		
		String sql = "select * from tbAlarmRec ";
		if(null!=workshop&&!"".equals(workshop))
		{
			sql += " and WorkshopCode = '"+workshop+"'";
		}
		if(null!=machineCode&&!"".equals(machineCode))
		{
			sql += " and MachineCode = '"+machineCode+"'";
		}
		if(null!=startTime&&!"".equals(startTime))
		{
			sql += " and RecTime > '"+startTime+"'";
		}
		if(null!=endTime&&!"".equals(endTime))
		{
			sql += " and RecTime < '"+endTime+"'";
		}		
		List<AlarmRec>  list = this.getJdbcTemplate().query(
			   sql,
			    new RowMapper() {

			        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
			        	AlarmRec rec = new AlarmRec();
			        	rec.setWorkshopCode(rs.getString("WorkshopCode"));
			        	rec.setMachineCode(rs.getString("MachineCode"));
			        	rec.setRecTime(rs.getString("RecTime"));
			        	rec.setDuration(rs.getInt("Duration"));
			        	rec.setStateType(rs.getString("StateType"));
		        	
			            return rec;
			        }
			    });
		return list;
	}
}
